// 例：abbccccaaa->a1b2c4a3


function zipStr(str) {
    let cur = 0
    let num = 1
    let res = ''
    for (let i = 1; i < str.length; i ++) {
        if (str.charAt(i) === str.charAt(cur)) {
            num ++
        }
        else {
            res += str.charAt(cur) + num;
            cur = i
            num = 1
        }
    }
    // 最后一轮加不进去
    res += str.charAt(cur) + num
    return res
}

console.log(zipStr('abbccccaaa'));
